package service;

import bean.Permissions;
import bean.Role;
import bean.User;
import org.springframework.stereotype.Service;
import service.inter.LoginService;

import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service
public class LoginServiceImpl implements LoginService {

    @Override
    public User getUserByName(String name) {
        return getByName(name);
    }

    /**
     * 模拟查询用户
     *
     * @param userName
     * @return
     */
    private User getByName(String userName) {
        // 1. 权限
        Permissions permissions1 = new Permissions("p1", "query");
        Permissions permissions2 = new Permissions("p2", "add");
        Set<Permissions> permissionSet = Stream.of(permissions1, permissions2).collect(Collectors.toSet());

        // 2. 角色
        Role role = new Role("r1", "admin", permissionSet);
        Set<Role> roleSet = Stream.of(role).collect(Collectors.toSet());

        // 3. 用户
        User user = new User("u1", "user", "user123", roleSet);
        return user;
    }
}
